﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Warehouse : FormBase1
    {
        public Warehouse()
        {
            InitializeComponent();
        }

        private void Warehouse_Load(object sender, EventArgs e)
        {
            rle_shop.DataSource = my.bw.View_shop_lite_Get(my.ACID);
            rle_shop.DisplayMember = "name";
            rle_shop.ValueMember = "shopcode";
            bind("");
        }

        private void bind(string wid)
        {
            gridControl1.DataSource = my.bw.Warehouse_Get("WarehouseID", my.ACID);
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Warehouse_N frm = new Warehouse_N();
            frm.FatherRefresh1 = bind;
            frm.Show(this);
        }

        private void btn_update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SVC.client.Warehouse cur = null;
            try
            {
                cur = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Warehouse;
            }
            catch { }
            if (cur != null)
            {
                Warehouse_U frm = new Warehouse_U(cur);
                frm.FatherRefresh = bind;
                frm.Show(this);
            }

        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle < 0)
            {

                btn_update.Enabled = btn_delete.Enabled = false;
            }
            else
            {
                btn_update.Enabled = btn_delete.Enabled = true;
            }
        }

        private void btn_delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            SVC.client.Warehouse cur = null;
            try
            {
                cur = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Warehouse;
            }
            catch { }
            if (cur != null)
            {
                if (DialogResult.No == XtraMessageBox.Show("你确定要删除当前焦点行数据？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2))
                {
                    return;
                }
                string r = my.bw.WarehouseByWarehouseID_Delete(cur.WarehouseID, my.ACID);
                if (string.IsNullOrWhiteSpace(r))
                {
                    bind("");
                }
                else
                {
                    Comm.ShowErorr(r);
                }
            }
        }

        private void btn_sx_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bind("");
        }
    }
}